package com.ruoyi.system.controller;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.DivineCase;
import com.ruoyi.system.service.IDivineCaseService;

/**
 * 卡牌问答的案例Controller
 * 
 * @author DEREK
 * @date 2023-10-12
 */
@RestController
@RequestMapping("/system/divineCase")
public class DivineCaseController extends BaseController
{
    @Autowired
    private IDivineCaseService divineCaseService;

    /**
     * 查询卡牌问答的案例列表
     */
    @PreAuthorize("@ss.hasPermi('system:divineCase:list')")
    @GetMapping("/list")
    public TableDataInfo list(DivineCase divineCase)
    {
        startPage();
        List<DivineCase> list = divineCaseService.selectDivineCaseList(divineCase);
        return getDataTable(list);
    }

    /**
     * 导出卡牌问答的案例列表
     */
    @PreAuthorize("@ss.hasPermi('system:divineCase:export')")
    @Log(title = "卡牌问答的案例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DivineCase divineCase)
    {
        List<DivineCase> list = divineCaseService.selectDivineCaseList(divineCase);
        ExcelUtil<DivineCase> util = new ExcelUtil<DivineCase>(DivineCase.class);
        util.exportExcel(response, list, "卡牌问答的案例数据");
    }

    /**
     * 获取卡牌问答的案例详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:divineCase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
    	DivineCase selectDivineCaseById = divineCaseService.getById(id);
    	if(StringUtils.isNotEmpty(selectDivineCaseById.getImg())) {
    		String[] split = selectDivineCaseById.getImg().split(",");
    		selectDivineCaseById.setSimpleSpectrum1(Arrays.asList(split));
    	}
        return AjaxResult.success(selectDivineCaseById);
    }

    /**
     * 新增卡牌问答的案例
     */
    @PreAuthorize("@ss.hasPermi('system:divineCase:add')")
    @Log(title = "卡牌问答的案例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DivineCase divineCase)
    {
        return toAjax(divineCaseService.save(divineCase));
    }

    /**
     * 修改卡牌问答的案例
     */
    @PreAuthorize("@ss.hasPermi('system:divineCase:edit')")
    @Log(title = "卡牌问答的案例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DivineCase divineCase)
    {
        return toAjax(divineCaseService.updateById(divineCase));
    }

    /**
     * 删除卡牌问答的案例
     */
    @PreAuthorize("@ss.hasPermi('system:divineCase:remove')")
    @Log(title = "卡牌问答的案例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(divineCaseService.deleteDivineCaseByIds(ids));
    }
}
